/**
 *
 */
package com.note.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;

import com.uosit.widget.InkEditor;
import com.uosit.widget.inkEditor.InkContext;
import com.uosit.widget.inkEditor.canvas.CanvasView;

//import com.uosit.widget.InkEditor;
//import com.uosit.widget.InkEditor.SupportedShape;
//import com.uosit.widget.inkEditor.InkContext;
//import com.uosit.widget.inkEditor.canvas.CanvasView;

/**
 * the widget for edit a SVG file
 */
public class SVGEditor extends InkEditor {
	/**
	 * (non-Javadoc)
	 *
	 * @see android.view.View#View(android.content.Context)
	 */
	public SVGEditor(Context context) {
		super(context);
	}

	/**
	 * (non-Javadoc)
	 *
	 * @see android.view.View#View(android.content.Context,
	 *      android.util.AttributeSet)
	 */
	public SVGEditor(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public InkContext getInkContext() {
		if (gContext == null) {
			gContext = SVGContext.getInstance();
		}
		return gContext;
	}

	public void parse(byte[] data, byte[] imageBuffer, String textBuffer) {
		mSvgCanvas.parse(data, imageBuffer, textBuffer);
		invalidate();
	}

	public byte[] getImageBuffer() {
		return mSvgCanvas.getSvgBrowser().getImageBuffer();
	}

	public String getTextBuffer() {
		return mSvgCanvas.getSvgBrowser().getTextBuffer();
	}

	/**
	 *
	 * @return XML string
	 */
	public String getSvgString() {
		return mSvgCanvas.getSvgBrowser().getXMLString();
	}

	/**
	 *
	 * @param xmlString
	 */
	public void setSvgString(String xmlString) {
		mSvgCanvas.setSVGString(xmlString);
		invalidate();
	}

	public void newSvgDocument(float width, float height) {
		mSvgCanvas.getSvgBrowser().newSvgDocument(width, height);
	}

	/**
	 *
	 * @param width
	 * @param height
	 * @return
	 */
	public byte[] getSvgThumb(int width, int height) {
		return mSvgCanvas.getSvgBrowser().getThumbnail(width, height);
	}

	/**
	 *
	 * @param rect
	 * @return
	 */
	public byte[] getSvgRegion(Rect rect) {
		return mSvgCanvas.getSvgBrowser().getPartPicture(rect);
	}

	/**
	 *
	 * @param rect
	 * @param coor
	 * @return
	 */
	public int getSvgRecognize(RectF rect, int[] coor) {
		return mSvgCanvas.getSvgBrowser().getHandwriting(rect, coor);
	}

	public void svgRestart() {
		//mSvgCanvas.getSvgBrowser().svgBrowserOnRestart();
	}


	public void svgStop() {
		//mSvgCanvas.getSvgBrowser().svgBrowserOnStop();
	}

	/**
	 *
	 * @param uri
	 */
	public void setThemeImage(String uri) {
		//mSvgCanvas.getSvgBrowser().setBackgroundPicture(uri);
		//mCanvasView.invalidate();
	}

	public void addImage(Bitmap bitmap, RectF rectF) {

//		ImageShape shapeModule = (ImageShape)getAllShapes()[SupportedShape.Image.ordinal()];
//		shapeModule.addImage(mSvgCanvas, bitmap, rectF);
	}

	public void insertText(){
//		TextShape shapeModule = (TextShape)getAllShapes()[SupportedShape.Text.ordinal()];
//		shapeModule.insertText();
	}



	@Override
	protected void init() {
		if (mInkCanvas == null) {
			getAllShapes()[DEFAULT_SHAPE.ordinal()].notifyDrawingMode();
			mCanvasView = new CanvasView(mActivity);
			mSvgCanvas = new SVGCanvas(this);	// mCanvasView should be valid before
			mSvgCanvas.init();
			mInkCanvas = mSvgCanvas;
			mCanvasView.setCanvas(mInkCanvas);
		}
	}

	private SVGCanvas mSvgCanvas;

	public void SVGCanvas(){
		mSvgCanvas = new SVGCanvas(this);	//  added by Frank, to suport widget.
		mSvgCanvas.init();
		mInkCanvas = mSvgCanvas;
	}
}
